/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CreateItem.java
 *
 * Created on 16-06-2011, 09:09:45
 */
package GUILayer;
import ControlLayer.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alex
 */
public class CreateItem extends javax.swing.JFrame {

    private ItemController itemController;
    private SupplierController supplierController;
    /** Creates new form CreateItem */
    public CreateItem() {
        initComponents();
        itemController = new ItemController();
        supplierController = new SupplierController();
        
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        createItemPanel1 = new javax.swing.JPanel();
        tekstToLabel1 = new javax.swing.JLabel();
        enterBarcodeLabel1 = new javax.swing.JLabel();
        enterNameTextField1 = new javax.swing.JTextField();
        enterItemNumberLabel1 = new javax.swing.JLabel();
        enterItemNumberTextField2 = new javax.swing.JTextField();
        enterNameLabel1 = new javax.swing.JLabel();
        enterDescriptionLabel1 = new javax.swing.JLabel();
        enterBuyingPriceLabel1 = new javax.swing.JLabel();
        enterSellingPriceLabel1 = new javax.swing.JLabel();
        enterLocationNumberLabel1 = new javax.swing.JLabel();
        enterAmountInStockLabel1 = new javax.swing.JLabel();
        enterAmountPrOrderLabel1 = new javax.swing.JLabel();
        enterMinimumInStockLabel1 = new javax.swing.JLabel();
        enterMaximumInStockLabel1 = new javax.swing.JLabel();
        enterSuppplierLabel1 = new javax.swing.JLabel();
        enterBarcodeTextField2 = new javax.swing.JTextField();
        enterBuyingPriceTextField1 = new javax.swing.JTextField();
        enterSellingPriceTextField1 = new javax.swing.JTextField();
        enterLocationNumberTextField1 = new javax.swing.JTextField();
        enterAmountInStockTextField1 = new javax.swing.JTextField();
        enterAmountPrOrderTextField1 = new javax.swing.JTextField();
        enterMinimumInStockTextField1 = new javax.swing.JTextField();
        enterMaximumInStockTextField1 = new javax.swing.JTextField();
        enterSupplierTextField1 = new javax.swing.JTextField();
        okayCreateItemButton1 = new javax.swing.JButton();
        cancelCreateItemButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        enterDescriptionTextArea1 = new javax.swing.JTextArea();
        enterLocationNumberLabel2 = new javax.swing.JLabel();
        enterLocationNumberTextField2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        createItemPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Create item"));

        tekstToLabel1.setText("Enter the information of the item:");

        enterBarcodeLabel1.setText("Enter barcode:");

        enterItemNumberLabel1.setText("Enter item number:");

        enterItemNumberTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enterItemNumberTextField2ActionPerformed(evt);
            }
        });

        enterNameLabel1.setText("Enter name:");

        enterDescriptionLabel1.setText("Enter description:");

        enterBuyingPriceLabel1.setText("Enter buying price:");

        enterSellingPriceLabel1.setText("Enter selling price:");

        enterLocationNumberLabel1.setText("Enter location number:");

        enterAmountInStockLabel1.setText("Enter amount in stock:");

        enterAmountPrOrderLabel1.setText("Enter amount pr order:");

        enterMinimumInStockLabel1.setText("Enter minimum in stock:");

        enterMaximumInStockLabel1.setText("Enter maximum in stock:");

        enterSuppplierLabel1.setText("Enter supplier:");

        okayCreateItemButton1.setText("Create");
        okayCreateItemButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okayCreateItemButton1ActionPerformed(evt);
            }
        });

        cancelCreateItemButton1.setText("Cancel");
        cancelCreateItemButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelCreateItemButton1ActionPerformed(evt);
            }
        });

        enterDescriptionTextArea1.setColumns(20);
        enterDescriptionTextArea1.setRows(5);
        jScrollPane1.setViewportView(enterDescriptionTextArea1);

        enterLocationNumberLabel2.setText("Enter discount:");

        javax.swing.GroupLayout createItemPanel1Layout = new javax.swing.GroupLayout(createItemPanel1);
        createItemPanel1.setLayout(createItemPanel1Layout);
        createItemPanel1Layout.setHorizontalGroup(
            createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(createItemPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(enterLocationNumberLabel1)
                    .addComponent(enterLocationNumberLabel2))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(enterLocationNumberTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(enterLocationNumberTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(153, Short.MAX_VALUE))
            .addGroup(createItemPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(enterItemNumberLabel1)
                    .addComponent(enterNameLabel1)
                    .addComponent(enterBuyingPriceLabel1)
                    .addComponent(enterSellingPriceLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 34, Short.MAX_VALUE)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(enterSellingPriceTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(enterBuyingPriceTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(enterNameTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(enterItemNumberTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(enterBarcodeTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(154, 154, 154))
            .addGroup(createItemPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(tekstToLabel1)
                .addContainerGap(225, Short.MAX_VALUE))
            .addGroup(createItemPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(enterBarcodeLabel1)
                .addContainerGap(314, Short.MAX_VALUE))
            .addGroup(createItemPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(createItemPanel1Layout.createSequentialGroup()
                        .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(enterAmountInStockLabel1)
                            .addComponent(enterAmountPrOrderLabel1)
                            .addComponent(enterMinimumInStockLabel1)
                            .addComponent(enterMaximumInStockLabel1)
                            .addComponent(enterSuppplierLabel1)
                            .addComponent(enterDescriptionLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, createItemPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(enterAmountInStockTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(100, 100, 100))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, createItemPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(enterAmountPrOrderTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(100, 100, 100))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, createItemPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(enterMinimumInStockTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(100, 100, 100))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, createItemPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(enterMaximumInStockTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(100, 100, 100))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, createItemPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(enterSupplierTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(100, 100, 100))
                    .addGroup(createItemPanel1Layout.createSequentialGroup()
                        .addGap(126, 126, 126)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(createItemPanel1Layout.createSequentialGroup()
                        .addGap(126, 126, 126)
                        .addComponent(okayCreateItemButton1)
                        .addGap(18, 18, 18)
                        .addComponent(cancelCreateItemButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(54, Short.MAX_VALUE))
        );
        createItemPanel1Layout.setVerticalGroup(
            createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(createItemPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tekstToLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterBarcodeLabel1)
                    .addComponent(enterBarcodeTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterItemNumberLabel1)
                    .addComponent(enterItemNumberTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterNameLabel1)
                    .addComponent(enterNameTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterBuyingPriceLabel1)
                    .addComponent(enterBuyingPriceTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterSellingPriceLabel1)
                    .addComponent(enterSellingPriceTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(enterLocationNumberLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(createItemPanel1Layout.createSequentialGroup()
                        .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(enterLocationNumberTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(enterLocationNumberLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                        .addComponent(enterLocationNumberTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(17, 17, 17)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterAmountInStockLabel1)
                    .addComponent(enterAmountInStockTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterAmountPrOrderLabel1)
                    .addComponent(enterAmountPrOrderTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterMinimumInStockLabel1)
                    .addComponent(enterMinimumInStockTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterMaximumInStockLabel1)
                    .addComponent(enterMaximumInStockTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterSuppplierLabel1)
                    .addComponent(enterSupplierTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(createItemPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(createItemPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(okayCreateItemButton1)
                            .addComponent(cancelCreateItemButton1)))
                    .addComponent(enterDescriptionLabel1)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(createItemPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(createItemPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(23, 23, 23))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okayCreateItemButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okayCreateItemButton1ActionPerformed
        try {
            itemController.createItem(enterBarcodeTextField2.getText(), enterItemNumberTextField2.getText(), enterNameTextField1.getText(), Integer.parseInt(enterAmountPrOrderTextField1.getText()), enterDescriptionTextArea1.getText(), Integer.parseInt(enterBuyingPriceTextField1.getText()), Integer.parseInt(enterSellingPriceTextField1.getText()), enterLocationNumberTextField1.getText(), supplierController.findSupplier(enterSupplierTextField1.getText()), Integer.parseInt(enterAmountInStockTextField1.getText()), Integer.parseInt(enterMinimumInStockTextField1.getText()), Integer.parseInt(enterMaximumInStockTextField1.getText()));
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        this.dispose();
    }//GEN-LAST:event_okayCreateItemButton1ActionPerformed

    private void cancelCreateItemButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelCreateItemButton1ActionPerformed
       this.dispose();
    }//GEN-LAST:event_cancelCreateItemButton1ActionPerformed

    private void enterItemNumberTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enterItemNumberTextField2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_enterItemNumberTextField2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelCreateItemButton1;
    private javax.swing.JPanel createItemPanel1;
    private javax.swing.JLabel enterAmountInStockLabel1;
    private javax.swing.JTextField enterAmountInStockTextField1;
    private javax.swing.JLabel enterAmountPrOrderLabel1;
    private javax.swing.JTextField enterAmountPrOrderTextField1;
    private javax.swing.JLabel enterBarcodeLabel1;
    private javax.swing.JTextField enterBarcodeTextField2;
    private javax.swing.JLabel enterBuyingPriceLabel1;
    private javax.swing.JTextField enterBuyingPriceTextField1;
    private javax.swing.JLabel enterDescriptionLabel1;
    private javax.swing.JTextArea enterDescriptionTextArea1;
    private javax.swing.JLabel enterItemNumberLabel1;
    private javax.swing.JTextField enterItemNumberTextField2;
    private javax.swing.JLabel enterLocationNumberLabel1;
    private javax.swing.JLabel enterLocationNumberLabel2;
    private javax.swing.JTextField enterLocationNumberTextField1;
    private javax.swing.JTextField enterLocationNumberTextField2;
    private javax.swing.JLabel enterMaximumInStockLabel1;
    private javax.swing.JTextField enterMaximumInStockTextField1;
    private javax.swing.JLabel enterMinimumInStockLabel1;
    private javax.swing.JTextField enterMinimumInStockTextField1;
    private javax.swing.JLabel enterNameLabel1;
    private javax.swing.JTextField enterNameTextField1;
    private javax.swing.JLabel enterSellingPriceLabel1;
    private javax.swing.JTextField enterSellingPriceTextField1;
    private javax.swing.JTextField enterSupplierTextField1;
    private javax.swing.JLabel enterSuppplierLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton okayCreateItemButton1;
    private javax.swing.JLabel tekstToLabel1;
    // End of variables declaration//GEN-END:variables
}
